<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd  ='song';
$dbName ='gu';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}

$orderBy='ASC';
if (isset($_GET['fan'])){
    $orderBy='DESC';
}
if (isset($_GET['id'])){
    $sql="SELECT id,openid FROM `da` WHERE `nianji` IS NULL and id > ".$_GET['id']."  ORDER BY `id` ".$orderBy." LIMIT 0,1";
}else{
    $sql="SELECT id,openid FROM `da` WHERE `nianji` IS NULL ORDER BY `id` ".$orderBy." LIMIT 0,1";
}
$has=false;
$query=$mysqli->query($sql);
while ($list=$query->fetch_assoc()){
    $has=true;
    var_dump($list);
    echo "<br /><br />";
    $sql="SELECT nianji,mid FROM `check3` where openid='".$list['openid']."'  ";
    $queryCheck=$mysqli->query($sql);
    $checkList=$queryCheck->fetch_assoc();
     
    echo "<br />";
    echo var_dump($checkList);
    echo "<br /><br /><br />";
    
    $sqlUpdate="update da set nianji=".$checkList['nianji'].",mid=".$checkList['mid']." where id='".$list['id']."'  ";
    echo '........................................';
    echo $sqlUpdate;
    $mysqli->query($sqlUpdate);
    
}
//$mysqli->close();
?>

<?php if ($has){ ?>
<script> 
window.setTimeout(function(){
	window.location.reload(); 
}, 400);
</script>
<?php } ?>